package cn.kuang.controller;

import cn.kuang.pojo.Msg;
import cn.kuang.service.UserMsgService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 徽州大都督
 * @date 2020/7/23
 */
@RestController
@RequestMapping("msg")
public class UserMsgController {

    @Autowired
    private UserMsgService userMsgService;

    @PostMapping("addContent/{content}/{username}")
    public String addContent(@PathVariable("content")String content, @PathVariable("username")String username){
        // System.out.println (content);
        //System.out.println (username);

        userMsgService.addMsg(content,username);


        return "success";
    }



    /**
     * 分页查询
     *
     * @return
     */
    @GetMapping("/findPage/{page}/{size}")
    public List<Msg> findPage(@PathVariable("page") Integer page, @PathVariable("size") Integer size) {
       /* Pageable pageable = PageRequest.of (page - 1, size);  //页面从1开始的
        return userService.findAll (pageable);*/

        System.out.println (page+":"+size);
        //System.out.println (page);
        //System.out.println (size);
        /*Pageable pageable = PageRequest.of (page-1,size);

        registerUser (userService.findByPage(pageable));*/
        List<Msg> byPage = userMsgService.findByPage (page, size);

        return byPage;
    }
}
